package coder

func (c *clientImpl) WriteUID(uid []byte) (err error) {

	body := BuildNestedSubPacket(NestSubCmdDelayReq, uid)
	body = BuildNestedPacket(NestCmdWriteReq, body)

	var data = BuildPacket(CmdReqNested, body)

	go func() {
		packet := BuildPacket(CmdReqNested, data)
		_, _ = c.tx(packet)
	}()
	err = c.WaitResp(func(body []byte) error {
		return nil
	})
	return
}

func (c *clientImpl) WritePsw(password []byte) (err error) {

	body := BuildNestedSubPacket(NestSubCmdDelayReq, password)
	body = BuildNestedPacket(NestCmdWriteReq, body)

	var data = BuildPacket(CmdReqNested, body)

	go func() {
		packet := BuildPacket(CmdReqNested, data)
		_, _ = c.tx(packet)
	}()
	err = c.WaitResp(func(body []byte) error {
		return nil
	})
	return
}

func (c *clientImpl) WriteDelayTime(delay []byte) (err error) {

	body := BuildNestedSubPacket(NestSubCmdDelayReq, delay)
	body = append(body, delay...)
	body = BuildNestedPacket(NestCmdWriteReq, body)

	var data = BuildPacket(CmdReqNested, body)

	go func() {
		packet := BuildPacket(CmdReqNested, data)
		_, _ = c.tx(packet)
	}()
	err = c.WaitResp(func(body []byte) error {
		return nil
	})
	return
}

func (c *clientImpl) WriteCode(code []byte) (err error) {

	body := BuildNestedSubPacket(NestSubCmdDelayReq, code)
	body = BuildNestedPacket(NestCmdWriteReq, body)

	var data = BuildPacket(CmdReqNested, body)

	go func() {
		packet := BuildPacket(CmdReqNested, data)
		_, _ = c.tx(packet)
	}()
	err = c.WaitResp(func(body []byte) error {
		return nil
	})
	return
}
